package io.github.wangtisnruipopo.carscore.types;

import io.github.wangtisnruipopo.carscore.utils.CompareUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

public abstract class AbsValue<V extends ICode> implements IValue<V>, Comparable<AbsValue<V>> {

    @Getter
    @Setter
    protected V value;

    public abstract List<V> listSort();

    @Override
    public String getText() {
        if (this.value == null) return null;
        return this.value.getText();
    }

    @Override
    public int compareTo(AbsValue<V> o) {
        return CompareUtil.compareTo(this, o, listSort());
    }

    @Override
    public boolean equals(Object o) {
        if (o == null) return false;
        if (o instanceof ICode) {
            return ((ICode) o).getValue().equals(this.getValue().getValue());
        }
        return false;
    }
}
